package com.urguxxi.springdemo.exception;

import com.urguxxi.springdemo.dto.ResultDTO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.security.auth.login.LoginException;
import com.urguxxi.springdemo.exception.LoginExcetion;


@RestControllerAdvice
public class MyExceptionAdvice {

    @ExceptionHandler(LoginExcetion.class)
    public ResultDTO loginExceptionHandler(LoginExcetion e){
        return new ResultDTO(e.getCode(),e.getMsg());
    }



    @ExceptionHandler(Exception.class)
    public ResultDTO exceptionHandler(Exception e){

        //记录异常的异常日志，对于系统来说很正常
        //状态码需要动态处理
        return new ResultDTO(1002,e.getMessage());
    }


}
